#!/bin/bash

#1 获取输入参数个数，如果没有参数，直接退出
# FILE_COUNT=$#
# if((FILE_COUNT==0)); then
#     echo "错误：未传递文件参数端口！"
#     echo "用法：mongoDB.sh 2181"
#     exit;
# fi
# 开始下载
URL=https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.17.tgz
source ../linux/download_unzip.sh "mongodb" $URL


# >>> source 调用本脚本时可用变量
# >>> $FILE_PATH 文件绝对路径：/opt/software/mongodb-linux-x86_64-4.0.17.tgz
# >>> $FILE_EXTENSI 文件后缀：tgz
# >>> $File_HOME 软件HOME：/opt/module/mongodb/mongodb-linux-x86_64-4.0.17
# >>> $REPO_PATH 仓库目录：/opt/repository/mongodb

mkdir -p $File_HOME/single/data/db
mkdir -p $File_HOME/single/log
CONF_FILE=$File_HOME/single/mongo.conf


# 配置 mongoDB 配置
sudo cat >$CONF_FILE<<EOF
systemLog:
    destination: file
    path: "$File_HOME/single/log/mongod.log"
    logAppend: true
storage:
    dbPath: $File_HOME/single/data/db
    journal:
        enabled: true
processManagement:
    fork: true
net:
    # bindIp: 0.0.0.0,::
    bindIpAll: true
    port: 27017
setParameter:
    enableLocalhostAuthBypass: false
EOF

echo "$File_HOME/bin/mongod -f $CONF_FILE"
